﻿using ScottPlot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BYUStock.Comman
{
    public static class CandleParser
    {
        public static IOHLC[] CandleCollectionToIOHLCArray(CandleCollection candles)
        {
            return candles.Candles.Select(candle => new OHLC(candle.Open,
                                                             candle.High,
                                                             candle.Low,
                                                             candle.Close,
                                                             candle.Start,
                                                             candle.Span)).ToArray();
        }


        public static TimeSpan GetCandleTiemSpan(CandleSpan span)
        {
            switch (span)
            {
                case CandleSpan.Minute1:
                    return TimeSpan.FromMinutes(1);
                case CandleSpan.Minute5:
                    return TimeSpan.FromMinutes(5);
                case CandleSpan.Minute15:
                    return TimeSpan.FromMinutes(15);
                case CandleSpan.Minute30:
                    return TimeSpan.FromMinutes(30);
                case CandleSpan.Minute60:
                    return TimeSpan.FromMinutes(60);
                case CandleSpan.Minute120:
                    return TimeSpan.FromMinutes(120);
                case CandleSpan.Day:
                    return TimeSpan.FromDays(1);
                case CandleSpan.Week:
                    return TimeSpan.FromDays(7);
                case CandleSpan.Month:
                    return TimeSpan.FromDays(30);
                case CandleSpan.Year:
                    return TimeSpan.FromDays(365);
                default:
                    throw new NotImplementedException();
            }
        }

        
    }
}
